package com.sky.controller.user;

import com.sky.result.Result;
import com.sky.service.SetmealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class SetmealController {
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private RedisTemplate redisTemplate;
    @RequestMapping("/list")
    @Cacheable(cacheNames = "setmealCache", key = "#categoryId")
    public Result<List<SetmealVO>> list(@RequestParam Integer categoryId) {
        List<SetmealVO> list = setmealService.list(categoryId);
        return Result.success(list);
    }

    @RequestMapping("/dish/{id}")
    @Cacheable(cacheNames = "setmealDishCache", key = "#id")
    public Result<List<DishItemVO>> list(@PathVariable Long id) {
        List<DishItemVO> list = setmealService.dishItem(id);
        return Result.success(list);
    }
}
